import { useEffect } from "react";

export default function useVisible(cb: (visible: boolean)=>void){
  useEffect(()=>{
    const onChange = ()=>{
      cb(document.visibilityState === 'visible');
    }
    document.addEventListener('visibilitychange',onChange);
    return ()=>{
      document.removeEventListener('visibilitychange', onChange);
    }
  },[])
}
